package com.example.designpatterns.command;

import com.example.designpatterns.command.concrete.*;
import com.example.designpatterns.command.macro.MacroCommand;
import com.example.designpatterns.command.receiver.*;

/**
 * 命令模式演示类 - 展示命令模式的使用
 */
public class CommandPatternDemo {
    public static void main(String[] args) {
        // 创建接收者对象
        Light livingRoomLight = new Light("客厅");
        Light kitchenLight = new Light("厨房");
        Light bedroomLight = new Light("卧室");
        
        Stereo livingStereo = new Stereo("客厅");
        Door frontDoor = new Door("前门");
        
        System.out.println("=== 基本命令演示 ===");
        
        // 创建灯光相关的命令
        Command livingRoomLightOn = new LightOnCommand(livingRoomLight);
        Command livingRoomLightOff = new LightOffCommand(livingRoomLight);
        Command kitchenLightOn = new LightOnCommand(kitchenLight);
        Command kitchenLightOff = new LightOffCommand(kitchenLight);
        Command bedroomLightOn = new LightOnCommand(bedroomLight);
        Command bedroomLightOff = new LightOffCommand(bedroomLight);
        Command dimLivingRoomLight = new DimLightCommand(livingRoomLight, 30);
        
        // 创建音响相关的命令
        Command stereoOn = new StereoOnCommand(livingStereo);
        Command stereoOff = new StereoOffCommand(livingStereo);
        
        // 创建门相关的命令
        Command openDoor = new DoorOpenCommand(frontDoor);
        Command closeDoor = new DoorCloseCommand(frontDoor);
        
        // 执行基本命令
        livingRoomLightOn.execute();
        stereoOn.execute();
        dimLivingRoomLight.execute();
        System.out.println();
        
        // 撤销命令示例
        System.out.println("=== 撤销命令演示 ===");
        System.out.println("撤销调光命令:");
        dimLivingRoomLight.undo();
        System.out.println("撤销打开音响:");
        stereoOn.undo();
        System.out.println();
        
        // 创建宏命令
        System.out.println("=== 宏命令演示 ===");
        
        // 创建"回家"宏命令 - 打开客厅灯光，打开音响，开门
        MacroCommand homeCommand = new MacroCommand("回家模式");
        homeCommand.addCommand(livingRoomLightOn);
        homeCommand.addCommand(stereoOn);
        homeCommand.addCommand(openDoor);
        
        // 创建"离家"宏命令 - 关闭所有灯光，关闭音响，关门
        MacroCommand awayCommand = new MacroCommand("离家模式");
        awayCommand.addCommand(livingRoomLightOff);
        awayCommand.addCommand(kitchenLightOff);
        awayCommand.addCommand(bedroomLightOff);
        awayCommand.addCommand(stereoOff);
        awayCommand.addCommand(closeDoor);
        
        // 创建"睡眠"宏命令 - 打开卧室灯，关闭其他灯和音响
        MacroCommand sleepCommand = new MacroCommand("睡眠模式");
        sleepCommand.addCommand(bedroomLightOn);
        sleepCommand.addCommand(livingRoomLightOff);
        sleepCommand.addCommand(kitchenLightOff);
        sleepCommand.addCommand(stereoOff);
        
        // 执行宏命令
        System.out.println("执行'回家模式'宏命令:");
        homeCommand.execute();
        System.out.println();
        
        System.out.println("执行'睡眠模式'宏命令:");
        sleepCommand.execute();
        System.out.println();
        
        System.out.println("执行'离家模式'宏命令:");
        awayCommand.execute();
        System.out.println();
        
        // 撤销宏命令
        System.out.println("撤销'离家模式'宏命令:");
        awayCommand.undo();
    }
} 